package com.congee02.modelshellmvn.service;

import com.congee02.modelshellmvn.anno.NeedPermission;
import com.congee02.modelshellmvn.client.PlateRecognitionClient;
import com.congee02.modelshellmvn.entity.account.AccountRoleDefinition;
import com.congee02.modelshellmvn.entity.plate.vo.PlateRecognitionResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.net.URL;
import java.util.List;

@Service
@Slf4j
public class PlateRecognitionService {

    @Resource
    private PlateRecognitionClient plateRecognitionClient;

    @NeedPermission(AccountRoleDefinition.USER)
    public List<PlateRecognitionResult> recognizeByURL(URL imageURL) {
        return plateRecognitionClient.recognize(
                new UrlResource(imageURL)
        );
    }

    @NeedPermission(AccountRoleDefinition.USER)
    public List<PlateRecognitionResult> recognizeByResource(org.springframework.core.io.Resource resource) {
        return plateRecognitionClient.recognize(
                resource
        );
    }

}
